package id.net.iconpln.bb.client.tools;

import id.net.iconpln.bb.client.service.TransportRPCService;
import id.net.iconpln.bb.client.service.TransportRPCServiceAsync;
import id.net.iconpln.bb.client.util.ClientModule;

import java.util.List;
import java.util.Map;

import com.extjs.gxt.ui.client.core.FastMap;
import com.extjs.gxt.ui.client.store.ListStore;
import com.extjs.gxt.ui.client.widget.form.ComboBox;
import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.rpc.AsyncCallback;

public class ComboRakorPembangkit extends ComboBox{
	private final TransportRPCServiceAsync service = GWT.create(TransportRPCService.class);
	private ListStore store;
	
	public ComboRakorPembangkit(String id_pltu) {
		super();
		store = new ListStore();
		
		setName("no_rakor");  
	    setFieldLabel("No Rakor");
	    setEmptyText("Select Rakor...");  
	    setDisplayField("no_rakor");  
	    setWidth(150);  
	    setStore(store);  
	    setTypeAhead(true);  
	    setTriggerAction(TriggerAction.ALL); 
	    
	    Map map = new FastMap();
	    map.put("id_pltu", id_pltu);
	    service.getListPengendalian("RAKOR_BY_PEMBANGKIT", map, new AsyncCallback<List<Map>>() {
			public void onFailure(Throwable caught) {
				GWT.log(caught.getMessage(), null);
			}

			public void onSuccess(List<Map> result) {	
				store.removeAll();
				store.add(ClientModule.setListBaseModelFromListMap(result));
			}
		});
	
	}

	
}
